package com.znsb.msfq.adapter;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.znsb.msfq.R;
import com.znsb.msfq.activity.CommodityDetailsActivity;
import com.znsb.msfq.bean.CollectBean;
import com.znsb.msfq.bean.H2ShopItemBean;
import com.znsb.msfq.utils.ActivityUtil;
import com.znsb.msfq.utils.ImageLoader;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

import static com.znsb.msfq.app.ZnsbApp.mContext;

/**
 * @name：
 * @author： 杨 广
 * @phone： 17382373271
 * @createTime： 2017/2/18
 * @modifyTime： 2017/2/18
 * @explain：
 */

public class H2ShopRVAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<H2ShopItemBean> dataList;
    private Context context;


    public H2ShopRVAdapter(Context context, List<H2ShopItemBean> dataList) {
        this.context = context;
        this.dataList = dataList;
    }


    @Override
    public int getItemCount() {
        return dataList.size();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View layout = LayoutInflater.from(mContext).inflate(R.layout.item_home2_shop, parent, false);
        return new H2ShopRVAdapter.MyHolder(layout);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MyHolder) {
            final  int idnex=position;
            ((H2ShopRVAdapter.MyHolder) holder).h2f_tv_shopname.setText(dataList.get(position).title + "");
            ((H2ShopRVAdapter.MyHolder) holder).h2f_tv_shoppice.setText("¥："+dataList.get(position).price + "");
            ImageLoader.imageLoderNo(((H2ShopRVAdapter.MyHolder) holder).h2f_iv_shopimg,dataList.get(position).logo );
            ImageLoader.imageCircleLoder(((H2ShopRVAdapter.MyHolder) holder).h2f_iv_img,dataList.get(position).sourceLogo );
            ((H2ShopRVAdapter.MyHolder) holder).h2f_iv_layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (dataList.size() > idnex) {
                    Bundle bundle = new Bundle();
                    bundle.putInt("ids", dataList.get(idnex).id);
                    ActivityUtil.next(context, CommodityDetailsActivity.class, bundle);
                }
                }
            });
        }
    }

    class MyHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.h2f_iv_layout)
        RelativeLayout h2f_iv_layout;
        @Bind(R.id.h2f_iv_shopimg)
        ImageView h2f_iv_shopimg;
        @Bind(R.id.h2f_iv_img)
        ImageView h2f_iv_img;
        @Bind(R.id.h2f_tv_shopname)
        TextView h2f_tv_shopname;
        @Bind(R.id.h2f_tv_shoppice)
        TextView h2f_tv_shoppice;

        public MyHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
